<template>
	<view class="content" v-if="pageshow">
		<view class="" style="padding-bottom: 200rpx;">
			<view class="center">
				<view class="flexbetween flex_wrap">
					<view class="flexleft">
						<view class="image_ya">
							<image :src="dataAll.user.avatar_text" mode=""></image>
						</view>
						<view class="center_zi">
							<view class="word_hei">{{dataAll.user.nickname}}</view>
							<view class="hui">{{dataAll.createtime_text}}</view>
						</view>
					</view>
					<view class="flexleft">
						<image src="@/static/images/login/eyes.png" mode="" class="eye"></image>
						<view class="hui">{{dataAll.views}}</view>
					</view>
				</view>
				<view class="hei">{{dataAll.title}}</view>
				<view class="hui_zi">{{dataAll.des}}</view>
				<!-- 图片 -->
				<view class="flexleft margin_top flex_wrap">
					<view class="item_image_box flexcenter" v-for="(ite,index) in dataAll.images_text" @click="previewimg(index)">
						<view class="item_image">
							<image :src="ite" mode=""></image>
						</view>
					</view>
				</view>
			</view>
			<!-- 评论 -->
			<view class="section" v-if="list.total">
				<view class="comment">评论 ({{list.total}})</view>
				<view class="flexstart" v-for="item in list.data" :key="item.id">
					<view class="ya">
						<view class="image_ya">
							<image :src="item.user.avatar_text" mode=""></image>
						</view>
					</view>
					<view>
						<view class="lv">{{item.user.nickname}}</view>
						<view class="pinglunqu">{{item.reply}}</view>
						<view class="year">{{item.createtime_text}}</view>
					</view>
				</view>
			</view>
		</view>
		
		<!-- footer -->
		<view class="footer flexleft">
			<view>
				<input type="text" class="inp" placeholder="说点什么吧" maxlength="500" v-model="reply" confirm-type="search"
					@confirm="sendpl">
			</view>
			<view class="send" @click="sendpl">发送</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				listid: "",
				dataAll: {},
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				reply: "",
				pageshow: false
			}
		},
		onLoad(options) {
			this.listid = options.id
			this.getdetail()
			this.init()
		},
		methods: {
			previewimg(index) {//预览图片
				let i = this.dataAll.images_text; //获取当前页面的轮播图数据
				//uniapp预览轮播图
				uni.previewImage({
					current: index, //预览图片的下标
					urls: i //预览图片的地址，必须要数组形式，如果不是数组形式就转换成数组形式就可以
				})
			},
			sendpl() {
				if (!httpRequest.checkIsLogin()) {
					httpRequest.doLogin();
					return false;
				}
				if (this.reply == "") {
					httpRequest.toast("请输入要发送的内容")
					return false
				}
				httpRequest.request('/api/forum/addComment', 'GET', {
					forum_id: this.listid,
					reply: this.reply,
				}, false, false, true).then(res => {
					httpRequest.toast(res.msg);
					if (res.code == 1) {
						this.reply = ""
						this.init()
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			getdetail() {
				httpRequest.request('/api/forum/detail', 'GET', {
					id: this.listid
				}, false, false, true).then(res => {
					if (res.code == 1) {
						this.pageshow = true
						this.dataAll = res.data
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			homepage() {
				uni.navigateTo({
					url: '/pages/index/zhuye',
				})
			},
			// 获取行业咨询列表
			init(isPage, page) {
				let _this = this;
				httpRequest.request('/api/Forum/getReplyList', 'GET', {
					page: page || 1,
					limit: _this.limit,
					id: this.listid
				}, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}

				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},

		}
	}
</script>

<style lang="scss" scoped>
	.image_ya {
		width: 77rpx;
		height: 77rpx;
		border-radius: 50%;

		image {
			width: 100%;
			height: 100%;
			border-radius: 50%;
		}
	}

	.item_image_box {
		width: 25%;
	}

	.item_image {
		width: 144rpx;
		height: 144rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.content {
		background-color: #fafafa;
		overflow: hidden;
		min-height: 100vh;
		padding-top: 0rpx;
	}

	.center {
		margin-top: 30rpx;
		padding-bottom: 30rpx;
		background-color: #fff;
		padding: 30rpx 30rpx;
	}

	.section {
		margin-top: 30rpx;
		background-color: #fff;
		padding: 30rpx 30rpx;
	}

	.eye {
		width: 24rpx;
		height: 14rpx;
		background-size: 100% 100%;
		padding-right: 10rpx;
	}

	.center_zi {
		padding: 0rpx 20rpx;
	}

	.hei {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #000000;
		margin: 20rpx 0rpx;
	}

	.hui_zi {
		font-size: 28rpx;
		line-height: 45rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
	}

	.comment {
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #000000;
	}

	.ya {
		padding: 34rpx 19rpx 0rpx 30rpx;
	}

	.lv {
		font-size: 30rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #000000;
		padding-top: 30rpx;
	}

	.pinglunqu {
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
		padding-top: 5rpx;
	}

	.year {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
		padding-top: 17rpx;
	}

	.footer {
		position: fixed;
		bottom: 0rpx;
		background-color: #ffff;
		padding: 60rpx 30rpx;
		width: 100%;
		box-sizing: border-box;
	}

	.inp {
		width: 500rpx;
		height: 70rpx;
		background: #F3F3F3;
		border-radius: 60rpx 60rpx 60rpx 60rpx;
		padding-left: 25px;
		padding-right: 20rpx;
	}

	.send {
		width: 200rpx;
		font-size: 27rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #228DFF;
		padding: 0rpx 3rpx 0rpx 34rpx;
	}
</style>